<!-- dialogs/fastSearch.html -->
<button type="button" class="close" ng-click="close()" class="pull-right">&times;</button>
<div class="fastsearch series miniposter">
    <h1 translate-once>FASTSEARCH/hdr</h1>
    <form ng-submit="save()" novalidate id="fastSearchForm">
      <formly-form model="model" fields="fields"></formly-form>
    </form>
<!-- input box -->
    <h2 ng-show="!model.fsquery || model.fsquery == ''" style="text-align:center" translate-once>COMMON/type-your-search/lbl</h2>
<!-- series from favorites -->
    <div class="fs-container fs-posters" ng-class="{'active': searchResults.series.length > 0 || seriesLoading}">
      <h3 translate-once>FASTSEARCH/series-favorites/hdr</h3>
      <loading-spinner class="small" ng-show="seriesLoading"></loading-spinner>
      <div class="fs-series no-animate" ng-if="searchResults.series.length > 0 && !seriesLoading">
        <serieheader ng-repeat="serie in searchResults.series  | orderBy: 'name' | limitTo: 6 track by serie.ID_Serie" data="serie" mode="poster" no-badge="1" no-title="0" no-overview="1" ng-click="close()" class="no-animate"></serieheader>
      </div>
    </div>
<!-- series from trakt.tv -->
    <div class="fs-container fs-posters" ng-class="{'active': searchResults.traktSeries.length > 0 || traktSeriesLoading}">
      <h3 translate-once>FASTSEARCH/series-trakttv/hdr</h3>
      <loading-spinner class="small" ng-show="traktSeriesLoading"></loading-spinner>
      <div class="fs-traktseries no-animate" ng-if="searchResults.traktSeries.length > 0 && !traktSeriesLoading">
        <serieheader ng-repeat="serie in searchResults.traktSeries | limitTo: 6 track by $index" data="serie" mode="poster" no-badge="1" no-title="0" no-overview="1" ng-click="addTraktSerie(serie)" class="no-animate">
        <em class="earmark" ng-show="isAdded(serie.trakt_id)"><i class='glyphicon glyphicon-ok'></i></em>
        <em class="earmark adding" ng-show="isAdding(serie.trakt_id)"><loading-spinner style="width: 37px; height:37px;"></loading-spinner></em>
        <em class="earmark error" ng-show="isError(serie.trakt_id)" uib-tooltip="{{error[serie.trakt_id]}}" tooltip-append-to-body="true" > :( </em>
        </serieheader>
      </div>
    </div>
<!-- list of episodes -->
    <div class="fs-container fs-list" ng-class="{'active' : searchResults.episodes.length > 0 || episodesLoading}">
      <h3 translate-once>FASTSEARCH/episodes-favorites/hdr</h3>
      <loading-spinner class="small" ng-show="episodesLoading"></loading-spinner>
      <div class="episodes" ng-if="searchResults.episodes.length > 0 && !episodesLoading">
        <table style='width:100%'>
          <tr ng-click="close()" ng-repeat="episode in searchResults.episodes | limitTo: 9 track by $index">
            <td><a ui-sref="episode({episode_id: episode.ID_Episode})">{{episode.getFormattedEpisode()}}</a></td>
            <td><a ui-sref="episode({episode_id: episode.ID_Episode})">{{getSerie(episode).name}}</a></td>
            <td><a ui-sref="episode({episode_id: episode.ID_Episode})">{{episode.episodename}}</a></td>
            <td>{{episode.firstaired |date:'short'}}</td>
            <td>
            <div ng-show="episode.hasAired() && getSetting('torrenting.enabled')">
             <torrent-dialog episode="episode" serie="getSerie(episode)"></torrent-dialog>
             <a class="auto-download" ng-click="fastSearch.autoDownload(sidepanel.serie, episode)" uib-tooltip="{{'COMMON/auto-download/lbl'|translate}}"><i class="glyphicon glyphicon-cloud-download"></i></a>
            </div>
          </tr>
        </table>
      </div>
    </div>
<!-- list of torrents -->
    <div class="fs-container fs-list torrents" ng-class="{'active' : searchResults.torrents.length > 0 || torrentsLoading}" ng-if="getSetting('torrenting.enabled')">
      <h3 translate-once>FASTSEARCH/torrents/hdr</h3>
      <loading-spinner class="small" ng-show="torrentsLoading"></loading-spinner>
      <div ng-if="searchResults.torrents.length > 0 || !torrentsLoading">
        <table class="torrents table table-condensed white" style="margin-bottom: 0">
          <tr>
            <th>&nbsp;</th>
            <th>
              <strong translate-once>COMMON/torrent-name/lbl</strong>
            </th>
            <th>
              <strong translate-once>COMMON/torrent-size/lbl</strong>
            </th>
            <th>
              <strong translate-once>COMMON/torrent-seed/lbl</strong>
            </th>
            <th>
              <strong translate-once>COMMON/torrent-leech/lbl</strong>
            </th>
          </tr>
          <tr ng-repeat="seed in searchResults.torrents | limitTo: 9" class="no-animate">
            <td style='width:80px; padding:5px; vertical-align: top;'>
              <a ng-if="!seed.noMagnet" ng-click="select(seed)">
                <i class="glyphicon glyphicon-magnet" uib-tooltip="{{'COMMON/download-magnet/tooltip'|translate}}"></i>
              </a>
              <a ng-if="seed.noMagnet">
                <i class="glyphicon glyphicon-magnet" style="color:gray"></i>
              </a>
              <a ng-if="!seed.noTorrent" ng-click="select(seed)">
                <i class="glyphicon glyphicon-download" uib-tooltip="{{'COMMON/download-torrent/tooltip'|translate}}"></i>
              </a>
              <a ng-if="seed.noTorrent">
                <i class="glyphicon glyphicon-download" style="color:gray"></i>
              </a>
              <!-- sneaky: update the $scope.seed with a dangling ref to the magic hash fetched from a promise.
                   It's leaking memory until the torrent dialog is closed, won't be much of a problem imo. -->
              <a ng-if="!seed.noMagnet" ng-href="{{seed.magnetUrl}}" ng-click="seed=submitMagnetLink(seed)">
                <i class="glyphicon glyphicon-link" uib-tooltip="{{'COMMON/magnet-link/tooltip'|translate}}"></i>
              </a>
              <a ng-if="seed.noMagnet">
                <i class="glyphicon glyphicon-link" style="color:gray"></i>
              </a>
              <a ng-if="seed.detailUrl" ng-href="{{::seed.detailUrl}}" target='_blank'>
                <i class="glyphicon glyphicon-info-sign" uib-tooltip="{{'COMMON/torrent-details/lbl'|translate}}"></i>
              </a>
              <a ng-if="!seed.detailUrl">
                <i class="glyphicon glyphicon-info-sign" style="color:gray"></i>
              </a>
            </td>
            <td>
              <a ng-bind-html="::seed.releasename | unsafe" ng-click="select(seed)"></a>
            </td>
            <td>
              <a ng-bind-html="::seed.size" ng-click="select(seed)" style='white-space:nowrap'></a>
            </td>
            <td style='width:50px; text-align:right'>
              <a  ng-bind="::seed.seeders" ng-click="select(seed)"></a>
            </td>
            <td style='width:50px; text-align:right'>
              <a  ng-bind="::seed.leechers" ng-click="select(seed)"></a>
            </td>
          </tr>
        </table>
      </div>
    </div>

</div>
